<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>修改密码</title>
    <meta name="viewport" content="width=device-width" />
    <link href="../../js/jquery-easyui-1.4/themes/default/easyui.css" rel="stylesheet"
          type="text/css" />
    <link href="../../js/jquery-easyui-1.4/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-easyui-1.4/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.4/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.4/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.4/easyui-validate.js" type="text/javascript"></script>
    <script src="/js/base.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //获取并显示原始数据，如：用户名。
            $.getJSON("/User", { action: "getLoginUser", r: Math.random() }, function (data) {
                    if(data.success === false){
                        $.messager.alert("出错了", data.msg, 'error',function(){
                            top.window.location.replace("Login.jsp");
                        });
                    }else{
                        $("#username").textbox("setValue",data.username);
                    }
            }).error(function () {
                alert("系统错误,请刷新界面后重试");
            });
        });

        function reset() {
            $("#oldPassword,#newPassword,#newPassword2").textbox("setValue", "");
        }

        function submitForm() {
            var fj = $("#fm").serializeJson();
            var newPassword = fj.newPassword;
            var newPassword2 = fj.newPassword2;
            var oldPassword = fj.oldPassword;
            if (oldPassword.length == 0 || newPassword.length == 0 || newPassword2.length == 0) {
                $.messager.alert('警告', '输入框不能为空', 'info');
                return;
            }
            if (newPassword != newPassword2) {
                $("#newPassword").focus();
                $.messager.alert('警告', '新密码两次输入不一致', 'info', function () {
                    $("#newPassword,#newPassword2").textbox("clear");
                    $('#newPassword').textbox().next('span').find('input').focus()
                });
                return;
            }

            $.messager.progress();

            fj.action = "modifyPassword";
            $.post("/User",fj,function(result){
                if(result.success === false){
                    $.messager.alert("出错",result.msg,"error");
                    return;
                }
                $.messager.alert('成功', '修改密码成功', 'info', function () {
                    top.window.location.replace("/User?action=logout");
                });
            },"json").error(onError).complete(function(){
                $.messager.progress("close");
            });



        }
    </script>
    <style type="text/css">
        body
        {
            margin: 1px !important;
            padding: 0;
        }

        .content
        {
            width: 400px;
            margin: 100px auto;
        }
    </style>
</head>
<body>
<div class="content">
    <div id="p" class="easyui-panel" data-options="iconCls:'icon-user'" title="用户信息"
         style="width: 100%; height: 290px;">
        <div style="padding: 10px 60px 20px 60px">
            <form id="fm" method="post">
                <table cellpadding="5">
                    <tr>
                        <td>用&nbsp;户&nbsp;名:
                        </td>
                        <td>
                            <input class="easyui-textbox" data-options="readonly:true" type="text" id="username" name="username" value=""></input>
                        </td>
                    </tr>
                    <tr>
                        <td>原&nbsp;密&nbsp;码:
                        </td>
                        <td>
                            <input class="easyui-textbox" type="password" id="oldPassword" name="oldPassword" />
                        </td>
                    </tr>
                    <tr>
                        <td>新&nbsp;密&nbsp;码:
                        </td>
                        <td>
                            <input class="easyui-textbox" type="password" id="newPassword" name="newPassword" />
                        </td>
                    </tr>
                    <tr>
                        <td>确认新密码:
                        </td>
                        <td>
                            <input class="easyui-textbox" type="password" id="newPassword2" name="newPassword2" />
                        </td>
                    </tr>
                </table>
            </form>
            <div style="text-align: center; padding: 5px">
                <a href="javascript:void(0)" data-options="iconCls:'icon-ok'" class="easyui-linkbutton" id="btn_modify"
                   onclick="submitForm()">修 改</a> <a href="javascript:void(0)" data-options="iconCls:'icon-cancel'"
                                                     class="easyui-linkbutton" onclick="reset();">重 置</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>
